import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)
let homePath = [
  {
    path: '/home/staticpage',
    name: 'staticpage',
    component: () => import('../views/home/Staticpage.vue'),
    meta: {
      title: "基础配置管理",
      isflag: true,
      icon: "home-o"
    }
  },
  {
    path: '/home/user',
    name: 'user',
    component: () => import('../views/home/User.vue'),
    meta: {
      title: "用户管理",
      isflag: true,
      icon: "home-o"
    }
  },
  {
    path: '/home/menu',
    name: 'menu',
    component: () => import('../views/home/Menu.vue'),
    meta: {
      title: "菜单管理",
      isflag: true,
      icon: "label-o"
    }
  },
  {
    path: '/home/person',
    name: 'person',
    component: () => import('../views/home/Person.vue'),
    meta: {
      title: "角色组管理",
      isflag: true,
      icon: "search"
    }
  },
  {
    path: '/home/type',
    name: 'type',
    component: () => import('../views/home/Type.vue'),
    meta: {
      title: "角色类型管理",
      isflag: true,
      icon: "setting-o"
    }
  },
  {
    path: '/home/done',
    name: 'user',
    component: () => import('../views/home/Done.vue'),
    meta: {
      title: "操作日志",
      isflag: true,
      icon: "friends-o"
    }
  },
]
const routes = [
  {
    path: '/',
    redirect: '/home/done', // 重定向:重新指向其它path,会改变网址
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    children: homePath
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  },
  
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 导航守卫
let whiteList = ["/home/classify", "/login", "/home/user", ]
router.beforeEach((to, from, next) => {
  let token = window.localStorage.getItem("token");
  if (token || whiteList.includes(to.path)) {
    next()
  } else {
    next("/login")
  }

})

export default router